package org.kk.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * the type of springcloud-alibaba
 *
 * <p>
 * .
 *
 * @author 铁甲小宝
 * @date 2022-12-06
 */
@Service
public class NacosConsumerService {

    @Autowired
    private LoadBalancerClient loadBalancerClient;
    @Autowired
    private RestTemplate restTemplate;
    @Value("${spring.application.name}")
    private String appName;
    @Value("${service-url.nacos-user-service}")
    private String serviceId;

    public String name(){
        ServiceInstance serviceInstance = loadBalancerClient.choose(serviceId);
        String path = serviceId + "/getName";
        System.out.println("request path:" +path);
        return restTemplate.getForObject(path, String.class);
    }
}
